﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using Heb2RusEngine;

namespace Heb2RusGui
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void btnTranslit_Click(object sender, EventArgs e)
        {
            string hebrewText = textBoxHebrew.Text;
            Hebrew2RussianTranslit translit = new Hebrew2RussianTranslit {Statement = new StatementProcessing()};
            string russianTranslitText = translit.ConvertLine(hebrewText);            
            textBoxRussianTranslit.Text = russianTranslitText;
        }

        private void popupTextBoxMenu_Opening(object sender, CancelEventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();
            menuItemPaste.Enabled = iData.GetDataPresent(DataFormats.Text);
            if (textBoxHebrew.SelectionLength == 0)
            {
                menuItemCut.Enabled = false;
                menuItemCopy.Enabled = false;
            }
            else
            {
                menuItemCut.Enabled = true;
                menuItemCopy.Enabled = true;
            }
        }

        private void menuItemSelectAll_Click(object sender, EventArgs e)
        {
            textBoxHebrew.SelectAll();
        }

        private void menuItemCut_Click(object sender, EventArgs e)
        {
            textBoxHebrew.Cut();
        }

        private void menuItemCopy_Click(object sender, EventArgs e)
        {
            textBoxHebrew.Copy();
        }

        private void menuItemPaste_Click(object sender, EventArgs e)
        {
            textBoxHebrew.Paste();
        }

        private void rusCopyMenuItem_Click(object sender, EventArgs e)
        {
            textBoxRussianTranslit.Copy();
        }

        private void popupMenu4Russian_Opening(object sender, CancelEventArgs e)
        {
            IDataObject iData = Clipboard.GetDataObject();
            if (textBoxRussianTranslit.SelectionLength == 0)
            {
                rusCopyMenuItem.Enabled = false;
            }
            else
            {
                rusCopyMenuItem.Enabled = true;
            }
        }

        private void rusSelectAllMenuItem_Click(object sender, EventArgs e)
        {
            textBoxRussianTranslit.SelectAll();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            Text += String.Format(" v{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision);
            textBoxHebrew.Text = "שָלוֹם ";
            btnTranslit.PerformClick();
            
        }
    }
}
